package com.android.youwenchuang.ui.adapter;

import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.android.youwenchuang.R;
import com.android.youwenchuang.bean.Goods;
import com.android.youwenchuang.bean.HomeBean;
import com.android.youwenchuang.bean.HomeGoodsBean;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;

import java.util.List;

public class HomeAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {
    public HomeAdapter() {
        addItemType(0, R.layout.item_banner);
        addItemType(1, R.layout.item_shop);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, MultiItemEntity item) {
        if (item.getItemType() == 0) {
            Banner banner = baseViewHolder.getView(R.id.banner);
            banner.setAdapter(new BannerImageAdapter<String>(((HomeBean) item).getPath()) {
                        @Override
                        public void onBindView(BannerImageHolder holder, String data, int position, int size) {
                            //图片加载自己实现
                            Glide.with(holder.itemView)
                                    .load(data)
                                    .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))
                                    .into(holder.imageView);
                        }
                    })
                    .setIndicator(new CircleIndicator(getContext()));
        } else {
            Goods goods = ((HomeGoodsBean) item).getGoods();
            baseViewHolder.setText(R.id.tv_name, goods.getName());
            baseViewHolder.setText(R.id.tv_price, "¥" + goods.getPrice());
            ImageView ivImage = baseViewHolder.getView(R.id.iv_image);
            Glide.with(getContext())
                    .load(goods.getPics())
                    .into(ivImage);
        }
    }
}
